package com.iweipan.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.iweipan.R;
import com.iweipan.bean.MyQuanListBean;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by xyb on 2016/12/22.
 */

public class MyQuanListAdapter extends BaseAdapter {

    private Context context;
    private ArrayList<MyQuanListBean.ResultBean> myQuanLists = new ArrayList<>();

    public MyQuanListAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return myQuanLists.size();
    }

    @Override
    public Object getItem(int position) {
        return myQuanLists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (viewHolder == null) {
            convertView = View.inflate(context, R.layout.myquan_list_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        MyQuanListBean.ResultBean item = (MyQuanListBean.ResultBean) getItem(position);
        String endTime = item.getEndTime();
        String startTime = item.getStartTime();
        int couponId = item.getCouponId();

        switch (couponId) {
            case 1:
                viewHolder.quanPrice.setText("8元");
                break;
            case 2:
                viewHolder.quanPrice.setText("80元");

                break;

            case 3:
                viewHolder.quanPrice.setText("200元");

                break;
        }
        viewHolder.quanTime.setText("有效期: " + startTime.substring(0, 10) + " 至 " + endTime.substring(0, 10));


        return convertView;
    }

    public void addLists(ArrayList<MyQuanListBean.ResultBean> myQuanLists) {
        this.myQuanLists = myQuanLists;
        notifyDataSetChanged();
    }


    static class ViewHolder {
        @BindView(R.id.img)
        ImageView img;
        @BindView(R.id.quan_price)
        TextView quanPrice;
        @BindView(R.id.quan_time)
        TextView quanTime;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
